<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\commands;

use app\models\Customer;
use yii\console\Controller;
use yii\console\ExitCode;
use Yii;
class HelloController extends Controller
{
    /*
     * 每天凌晨00：30检查是否有过期的
     */
    public function actionIndex()
    {
        $user = Customer::find()->all();
        $now_time = time();
        for ($i=0;$i<count($user);$i++){
            $due_time = $user[$i]->due_time.' 00:00:00';
            if ($now_time>strtotime($due_time)){
                $user[$i]->type=0;
                $user[$i]->code=1;
                $user[$i]->save();
                $address = 'address-'.$user[$i]->userid;
                $list = Yii::$app->cache->get($address);
                //修改redis里面的内容
                $list['due_time'] = $user[$i]->due_time;
                $list['type'] = 0;
                $list['code'] = 1;
                Yii::$app->cache->set($address,$list,3600*23);
            }
        }
    }
}
